package collection.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class StreamAPIDemo {
    public static void main(String[] args) {
        List<Integer>list=new ArrayList<>();
        for(int i=0;i<10;i++){
            list.add((int)(Math.random()*10));
        }
        System.out.println(list);

        List<Integer>list2=list.stream()//将集合变成流
                               .map(e->e*3)//添加map处理环节,三倍自身
                               .collect(Collectors.toList());
        System.out.println(list2);
        System.out.println(list);
        List<Integer>list3=list.stream().filter(e->e%2==0).collect(Collectors.toList());
        System.out.println(list3);
        List<Integer>list4=list.stream().distinct().collect(Collectors.toList());
        System.out.println(list4);
        List<Integer>list5=list.stream().sorted().collect(Collectors.toList());//升序
        List<Integer>list6=list.stream().sorted((o1,o2)->(o2-o1)).collect(Collectors.toList());//降序
        System.out.println(list5);
        System.out.println(list6);

        //对集合中每个元素扩大三倍并获取自重所有偶数然后去除重复元素然后降序排序
        List<Integer>list7=list.stream()
                               .map(e->e*3)
                               .filter(e->e%2==0)
                               .distinct()
                               .sorted((o1,o2)->(o2-o1))
                               .collect(Collectors.toList());
        System.out.println(list7);

    }
}
